/*
 * Created by JFormDesigner on Wed Dec 22 16:18:00 CST 2021
 */


package com.cn.项目.飞机预约管理系统.Maininterface;

import com.cn.项目.utils.JdbcUtils;



import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class DeleteFlight extends JPanel {
    public DeleteFlight() {
        initComponents();
    }

    private void button1ActionPerformed(ActionEvent e) {
        // TODO add your code here
        String date = null;
        String start = null;
        String end = null;
        Connection conn = null;
        PreparedStatement st = null;
        ResultSet rs = null;
        try {
            date = textField1.getText();
            start = textField2.getText();
            end = textField3.getText();
            conn =  JdbcUtils.getConnection();
            String sql="delete from flight where `traveldate`=?and start=?and `end`=?";
            st  =conn.prepareStatement(sql);
            st.setString(1,date );
            st.setString(2,start );
            st.setString(3,end);
            int i = st.executeUpdate();
            if (i>0){
                new Success();
            }else {
                new Fail();
            }
        } catch (SQLException e1) {
            e1.printStackTrace();
        }finally {
            JdbcUtils.release(conn,st ,rs);
        }
    }



    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();
        label2 = new JLabel();
        label3 = new JLabel();
        label4 = new JLabel();
        textField1 = new JTextField();
        textField2 = new JTextField();
        textField3 = new JTextField();
        button1 = new JButton();

        //======== this ========
        setLayout(null);

        //---- label1 ----
        label1.setText("\u5220\u9664\u98de\u673a\u822a\u73ed");
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 12f));
        add(label1);
        label1.setBounds(95, 15, 165, 40);

        //---- label2 ----
        label2.setText("\u51fa\u53d1\u65e5\u671f\uff1a");
        label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 6f));
        add(label2);
        label2.setBounds(5, 65, 110, 40);

        //---- label3 ----
        label3.setText("\u51fa\u53d1\u5730\uff1a");
        label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize() + 6f));
        add(label3);
        label3.setBounds(10, 120, 90, 40);

        //---- label4 ----
        label4.setText("\u76ee\u7684\u5730\uff1a");
        label4.setFont(label4.getFont().deriveFont(label4.getFont().getSize() + 6f));
        add(label4);
        label4.setBounds(10, 175, 90, 40);
        add(textField1);
        textField1.setBounds(125, 70, 150, 35);
        add(textField2);
        textField2.setBounds(125, 125, 150, 35);
        add(textField3);
        textField3.setBounds(125, 175, 150, 35);

        //---- button1 ----
        button1.setText("\u5220\u9664");
        button1.setFont(button1.getFont().deriveFont(button1.getFont().getSize() + 6f));
        button1.setForeground(new Color(255, 51, 0));
        button1.addActionListener(e -> button1ActionPerformed(e));
        add(button1);
        button1.setBounds(110, 230, 165, 40);

        { // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < getComponentCount(); i++) {
                Rectangle bounds = getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            setMinimumSize(preferredSize);
            setPreferredSize(preferredSize);
        }
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    private JLabel label2;
    private JLabel label3;
    private JLabel label4;
    private JTextField textField1;
    private JTextField textField2;
    private JTextField textField3;
    private JButton button1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
